home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / tcoop.arc / TCOOP2.ARC / TFSOUNIT.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1991-10-26  |  9.4 KB  |  308 lines

  1. // tfsounit.cpp: Tfso Class Implementation
  2.  
  3. #include <dos.h>
  4. #include "tfsounit.h"
  5.  
  6. // Set up a default TxBuff for Tfso and Tskel objects.
  7. // We use the current screen mode, and assume an 80x25 screen.
  8.  
  9. TxBuff ScrnBuff(80, 25, VideoPtr());
  10.  
  11. Tfso::Tfso(int Ba, int Fa, ColorPak &Cp)
  12. // Makes a text-based Fso. (We default the Trso's so that they 
  13. // use the full screen texel buffer). We set up the shadows and 
  14. // null out the swap buffer.
  15. : Fso(Ba, Fa, Cp)
  16. {
  17.   Overall  = new Trso(&ScrnBuff);  // Type as Trso's
  18.   Frame    = new Trso(&ScrnBuff); 
  19.   Interior = new Trso(&ScrnBuff); 
  20.   SaveBuff = NULL;   // To be allocated by SetSize
  21.   if (HasShadow()) { // Shadows are Tfso's themselves
  22.      HzShadow = new Tfso(0x00, Swappable, Cp);
  23.      VtShadow = new Tfso(0x00, Swappable, Cp);
  24.   }
  25.   else { // We don't have any shadows
  26.     HzShadow = NULL;  VtShadow = NULL;
  27.   }
  28. }
  29.  
  30. Tfso::~Tfso(void)
  31. // Destroy the save buffer and the shadow objects. 
  32. // Then destroy the frame rectangles.
  33. {
  34.   if (IsSwappable()) delete SaveBuff;
  35.   if (HasShadow()) { delete HzShadow; delete VtShadow; }
  36.   delete Frame; 
  37.   delete Interior;
  38.   delete Overall;
  39. }
  40.  
  41. void Tfso::SetSize(int W, int H)
  42. // The size (W,H) is interpreted to be the interior size. 
  43. // The other sizes are based off of it. Allocates space
  44. // for the save buffer if Swappable.
  45. {
  46.   Interior->SetSize(W, H);
  47.   Frame->SetSize(W+Bwd*2, H+Bwd*2);
  48.   if (HasShadow()) {
  49.      Overall->SetSize(Frame->Wd+2, Frame->Ht+1);
  50.      HzShadow->SetSize(Frame->Wd+1, 1);
  51.      VtShadow->SetSize(2, Frame->Ht-1);
  52.   }
  53.   else {
  54.      Overall->SetSize(Frame->Wd, Frame->Ht);
  55.   }
  56.   if (IsSwappable()) {
  57.      if (SaveBuff == NULL) {
  58.         SaveBuff = new Trso(NULL);
  59.      }
  60.      SaveBuff->SetSize(Frame->Wd, Frame->Ht);
  61.   }
  62. }
  63.  
  64. void Tfso::SetLocn(int Xl, int Yl)
  65. // Set the upper left hand corner location of the frames.
  66. // The location is interpreted to be that of the frame
  67. // rectangle. Also, set the shadow locations depending on
  68. // the type of shadow. 
  69. {
  70.   Frame->SetLocn(Xl, Yl);
  71.   Interior->SetLocn(Xl+Bwd, Yl+Bwd);
  72.   switch (Fattr & AnyShadow) {
  73.     case SEShadow: 
  74.       Overall->SetLocn(Frame->Xul, Frame->Yul);
  75.       HzShadow->SetLocn(Frame->Xul+1, Frame->Ylr+1);
  76.       VtShadow->SetLocn(Frame->Xlr+1, Frame->Yul+1);
  77.     break;
  78.     case NEShadow: 
  79.       Overall->SetLocn(Frame->Xul, Frame->Yul-1);
  80.       HzShadow->SetLocn(Frame->Xul+1, Frame->Yul-1);
  81.       VtShadow->SetLocn(Frame->Xlr+1, Frame->Yul);
  82.     break;
  83.     case NWShadow: 
  84.       Overall->SetLocn(Frame->Xul-2, Frame->Yul-1);
  85.       HzShadow->SetLocn(Frame->Xul-2, Frame->Yul-1);
  86.       VtShadow->SetLocn(Frame->Xul-2, Frame->Yul);
  87.     break;
  88.     case SWShadow: 
  89.       Overall->SetLocn(Frame->Xul-2, Frame->Yul);
  90.       HzShadow->SetLocn(Frame->Xul-2, Frame->Ylr+1);
  91.       VtShadow->SetLocn(Frame->Xul-2, Frame->Yul+1);
  92.     break;
  93.     default: // No shadow 
  94.       Overall->SetLocn(Frame->Xul, Frame->Yul);
  95.   }
  96. }
  97.  
  98. void Tfso::DrawFrame(char Ba, char Attr)
  99. // Draws the frame by simply drawing a box. A close button
  100. // is added if needed. 
  101. {
  102.   if (Bwd > 0) {
  103.      if (Ba == 0) Ba = (Bstyle << 4) + Bwd;
  104.      if (Attr == 0) Attr = Colors.Bc;
  105.      Frame->Box(0, 0, Frame->Wd, Frame->Ht, Ba, Attr);
  106.      if (IsCloseable())
  107.         Frame->HzWrt(1, 0, "\xb4\x08\xc3", Colors.Bc);
  108.   }
  109. }
  110.  
  111. int Tfso::OnCloseButton(int X, int Y)
  112. // Returns true if location (X,Y) is on the close button.
  113. // The close button is near the top left hand corner.
  114. {
  115.   return 
  116.     IsCloseable() && (Bwd > 0) && 
  117.     (Y == Frame->Yul) && (X == Frame->Xul + 2);
  118. }
  119.  
  120. void Tfso::Clear(char Ch, char Attr)
  121. // Clears the interior rectangle using the specified character
  122. // and attribute. The attribute can be defaulted to use the
  123. // value stored with the object.
  124. {
  125.   if (Attr > 0) Colors.Wc = Attr;
  126.   Interior->Fill(0, 0, Interior->Wd, Interior->Ht, Ch, Colors.Wc);
  127. }
  128.  
  129. void Tfso::GetImage(Rect *C)
  130. // Get the screen image region bounded by the frame rectangle
  131. // and store it in the save buffer (if there is one).
  132. // Get the shadow image too. C is the clipping rectangle
  133. // for the shadow.
  134. {
  135.   if (IsSwappable()) {
  136.      SaveBuff->
  137.        Xfr(0, 0, SaveBuff->Wd, SaveBuff->Ht, (Trso *)Frame, 0, 0);
  138.      DrawShadows(C, GetIm, False);
  139.   }
  140. }
  141.  
  142. void Tfso::PutImage(Rect *C)
  143. // Put the image stored in the save buffer (if there is
  144. // one) onto the screen at the region bounded by the frame 
  145. // rectangle. Put back the saved shadow buffer too. C is 
  146. // the clipping rectangle for the shadow.
  147. {
  148.   if (IsSwappable()) {
  149.      Trso *Tf = (Trso *)Frame;
  150.      Tf->Xfr(0, 0, Tf->Wd, Tf->Ht, SaveBuff, 0, 0);
  151.      DrawShadows(C, PutIm, False);
  152.   }
  153. }
  154.  
  155. void Tfso::Swap(Rect *C, XfrDirn Xd)
  156. // Swap the screen image bounded by the frame rectangle and the
  157. // save buffer. The Xfr direction Xd and clipping rectangle C
  158. // are used only for the shadows, which are drawn/erased accordingly.
  159. {
  160.   if (IsSwappable()) {
  161.      Trso *Tf = (Trso *)Frame;
  162.      Tf->Swap(0, 0, Tf->Wd, Tf->Ht, SaveBuff, 0, 0);
  163.      DrawShadows(C, Xd, True);
  164.   }
  165. }
  166.  
  167. void Tfso::DrawShadows(Rect *C, XfrDirn Xd, int DrawIt)
  168. {
  169.   if (HasShadow()) {
  170.      HzShadow->ShadowXfr(C, Xd, DrawIt);
  171.      VtShadow->ShadowXfr(C, Xd, DrawIt);
  172.   }
  173. }
  174.  
  175. void Tfso::ShadowXfr(Rect *C, XfrDirn Xd, int DrawIt)
  176. // Depending on Xd, either put the image in the shadow buffer
  177. // onto the screen, or get the image from the screen into
  178. // the buffer. If getting the image, and if DrawIt is True, 
  179. // after saving the screen image, draw the shadow 
  180. // by using a grey fill color. It's assumed this is a  
  181. // shadow, and it's assumed the buffer is not NULL. C is 
  182. // the clipping rectangle for the shadow. 
  183. {
  184.   int X, Y, W, H;
  185.   Trso *Tp = (Trso *)Overall;
  186.   X = Tp->Xul - C->Xul;  // Must compute coordinates relative
  187.   Y = Tp->Yul - C->Yul;  // to the clipping rectangle        
  188.   W = Tp->Wd; H = Tp->Ht;
  189.   if (C->HzClip(X, Y, W) && C->VtClip(X, Y, H)) {
  190.      X -= Tp->Xul - C->Xul; // Compute coordinates relative
  191.      Y -= Tp->Yul - C->Yul; // to the shadow
  192.      if (Xd == PutIm) {  // From buffer to screen
  193.         Tp->Xfr(X, Y, W, H, SaveBuff, 0, 0); 
  194.      }
  195.      else { // From screen to buffer, then possibly draw
  196.        SaveBuff->Xfr(0, 0, W, H, Tp, X, Y);
  197.        if (DrawIt) Tp->FillB(X, Y, W, H, 8, 1); // Grey fill
  198.      }
  199.   }
  200. }
  201.  
  202. // ----------- Now for the Text Skeleton Methods -----------
  203.  
  204. Tskel::Tskel(ColorPak &Cp)
  205. // Much like the Tfso class, except we have swap buffers for
  206. // the sides, and none for the interior. Sets the size to
  207. // 80x25. It's assumed the size will be changed during
  208. // moving/stretching. Setting it to 80x25 here will help
  209. // alleviate heap fragmentation. Border style has dashed lines, 
  210. // and frame style is swappable and stretchable.
  211. : Fso(0x31, Swappable+Stretchable, Cp) 
  212. {
  213.   int I;
  214.  
  215.   Overall  = new Trso(&ScrnBuff); // Type as Trso's
  216.   Frame    = new Trso(&ScrnBuff);
  217.   Interior = new Trso(&ScrnBuff);
  218.   for (I=0; I<4; I++) Sides[I] = NULL;
  219.   SetSize(80, 25); // This allocates the sides
  220. }
  221.  
  222.  
  223. Tskel::~Tskel(void)
  224. // Does away with the side swap buffers
  225. {
  226.   int I;
  227.   for (I=0; I<4; I++) delete Sides[I];
  228. }
  229.  
  230. void Tskel::SetSize(int W, int H)
  231. // Sets the size of the rectangles and the side swap buffers
  232. {
  233.   int I;
  234.  
  235.   Interior->SetSize(W, H);
  236.   Frame->SetSize(Interior->Wd+2, Interior->Ht+2);
  237.   Overall->SetSize(Interior->Wd+2, Interior->Ht+2);
  238.  
  239.   for (I=0; I<4; I++) {
  240.       if (Sides[I] == NULL) Sides[I] = new Trso(NULL);
  241.       if (I < 2) { // The top and bottom
  242.          Sides[I]->SetSize(Frame->Wd, 1);
  243.       }
  244.       else { // the left and right sides
  245.          Sides[I]->SetSize(1, Frame->Ht);
  246.       }
  247.       Sides[I]->Pic->Fill(0, 0,  // Blank out the sides
  248.         Sides[I]->Pic->Wd, Sides[I]->Pic->Ht, ' ', Colors.Bc);
  249.   }
  250. }
  251.  
  252.  
  253. void Tskel::DrawFrame(char Ba, char Attr)
  254. // Just like the Tfso version
  255. {
  256.   if (Bwd > 0) {
  257.      if (Ba == 0) Ba = (Bstyle << 4) + Bwd;
  258.      if (Attr == 0) Attr = Colors.Bc;
  259.      Frame->Box(0, 0, Frame->Wd, Frame->Ht, Ba, Attr);
  260.   }
  261. }
  262.  
  263. void Tskel::GetImage(Rect *)
  264. // Get the sides from screen to buffer.
  265. // Note: we don't use the rectangle parameter.
  266. {
  267.   Trso *Tf = (Trso *)Frame;
  268.  
  269.   if ((Tf->Ht < 1) || (Tf->Wd < 1)) return;
  270.   Sides[0]->Xfr(0, 0, Tf->Wd, 1, Tf, 0, 0);             // Top row
  271.   Sides[1]->Xfr(0, 0, Tf->Wd, 1, Tf, 0, Tf->Ht-1);      // Bottom row
  272.   if (Tf->Ht > 2) {
  273.      Sides[2]->Xfr(0, 0, 1, Tf->Ht-2, Tf, 0, 1);        // Left side
  274.      Sides[3]->Xfr(0, 0, 1, Tf->Ht-2, Tf, Tf->Wd-1, 1); // Right side
  275.   }
  276. }
  277.  
  278. void Tskel::PutImage(Rect *)
  279. // Get the sides from buffer to screen.
  280. // Note: we don't use the rectangle parameter
  281. {
  282.   Trso *Tf = (Trso *)Frame;
  283.  
  284.   if ((Tf->Ht < 1) || (Tf->Wd < 1)) return;
  285.   Tf->Xfr(0, 0, Tf->Wd, 1, Sides[0], 0, 0);             // Top row
  286.   Tf->Xfr(0, Tf->Ht-1, Tf->Wd, 1, Sides[1], 0, 0);      // Bottom row
  287.   if (Tf->Ht > 2) {
  288.      Tf->Xfr(0, 1, 1, Tf->Ht-2, Sides[2], 0, 0);        // Left side
  289.      Tf->Xfr(Tf->Wd-1, 1, 1, Tf->Ht-2, Sides[3], 0, 0); // Right side
  290.   }
  291. }
  292.  
  293. void Tskel::Swap(Rect *, XfrDirn)
  294. // Swap save buffer image and frame buffer image.
  295. // Note: we don't use the parameters. 
  296. {
  297.   Trso *Tf = (Trso *)Frame;
  298.  
  299.   if ((Tf->Ht < 1) || (Tf->Wd < 1)) return;
  300.   Tf->Swap(0, 0, Tf->Wd, 1, Sides[0], 0, 0);             // Top row
  301.   Tf->Swap(0, Tf->Ht-1, Tf->Wd, 1, Sides[1], 0, 0);      // Bottom row
  302.   if (Tf->Ht > 2) {
  303.      Tf->Swap(0, 1, 1, Tf->Ht-2, Sides[2], 0, 0);        // Left side
  304.      Tf->Swap(Tf->Wd-1, 1, 1, Tf->Ht-2, Sides[3], 0, 0); // Right side
  305.   }
  306. }
  307.  
  308.